//我们如何用状态机处理完全未知的 pattern？
function matchKmp(source,pattern){
    //计算table
    let table = new Array(pattern.length).fill(0);
    {
        let i = 1, j = 0;
        while(i<pattern.length){
            if(pattern[i]===pattern[j]){
                ++j,++i;
                table[i]=j
            }else{
                if(j > 0){
                    j = table[j];
                }else{
                    ++i;
                }
            }
        }
    }
    {
        let i = 0, j = 0; 
        while(i<source.length){
            
            if(pattern[j]===source[i]){
                ++j,++i;
            }else{
                if(j > 0){
                    j = table[j];
                }else{
                    ++i;
                }
            }
            if(j===pattern.length){
                return true
            }
        }
        return false;
    }
    console.log(table);
}
//aabaafaabaac

console.log(matchKmp("abcafsaba","aba"));